package pro.softzhang.algo.lc100;

/**
 * 169. 多数元素
 * https://leetcode.cn/problems/majority-element
 */
public class LC169_MajorityElement {
    public static void main(String[] args) {

    }

    /**
     *
     */
    static
    class Solution {
        public int majorityElement(int[] nums) {
            int majority = 0, votes = 0;
            for (int num : nums){
                if (votes == 0) {
                    majority = num;
                }
                votes += (num == majority ? 1 : -1);
            }
            return majority;
        }
    }
}
